package com.by.controller;

import com.by.entity.Student;
import com.by.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping("/getAll")
    @ResponseBody
    public List<Student> getAllStus() {
        return studentService.getAllStus();
    }

    @RequestMapping("/login")
    public String login(Student student, Model model) {
        Student stu = studentService.login(student);
        if (stu != null) {
            model.addAttribute("student", stu);
            return "succ";
        } else {
            return "login";
        }
    }
}
